﻿namespace TC
{
    public class SwitchInt_blueprint : TranslateBlueprint
    {
        public override editor.cfg.blueprint.Node OnTranslate(Node node)
        {
            SwitchInt t = node as SwitchInt;
            editor.cfg.blueprint.SwitchInt re = new editor.cfg.blueprint.SwitchInt();
            re.id = t.id;
            Port p = t.graph.GetConnect(t.selection);
            if(p == null)
            {
                re.selection = new editor.cfg.blueprint.ConstInt() { value = t.selection.defaultValue };
            }
            else
            {
                re.selection = new editor.cfg.blueprint.OutputPin() { nodeId = p.parent.id, pinName = p.name };
            }

            p = t.graph.GetConnect(t.defaultCase);
            if(p != null)
            {
                re.defaultCase = p.parent.id;
            }

            foreach(var i in t.cases)
            {
                p = t.graph.GetConnect(i.Value);
                if (p != null)
                {
                    re.cases.Add(i.Key, p.parent.id);
                }
            }

            return re;
        }
    }
}
